﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Collections.ObjectModel;

namespace Catalina.Dal
{
	public abstract class MapperBase<T>
	{
		protected abstract T Map(IDataRecord record);

		public Collection<T> MapAll(IDataReader reader)
		{
			Collection<T> collection = new Collection<T>();

			while (reader.Read())
			{
				try
				{
					collection.Add(Map(reader));
				}
				catch
				{
					throw;
				}
			}

			return collection;
		}

		protected static U FromDB<U>(object value)
		{
			return Convert.IsDBNull(value) ? default(U) : (U)value;
		}
	}
}
